package cn.zc.examination.service.service.impl;

import cn.tools.dozer.config.DozerUtils;
import cn.zc.examination.entity.Dto.ExaminationOptionDto;
import cn.zc.examination.entity.ExaminationOption;
import cn.zc.examination.service.mapper.ExaminationOptionMapper;
import cn.zc.examination.service.service.ExaminationOptionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 考试题选项 服务实现类
 * </p>
 *
 * @author keno
 * @since 2022-02-22
 */
@Service
public class ExaminationOptionServiceImpl extends ServiceImpl<ExaminationOptionMapper, ExaminationOption> implements ExaminationOptionService {

    @Resource
    private ExaminationOptionMapper examinationOptionMapper;

    @Resource
    private DozerUtils dozerUtils;

    /**
     * 创建题目选项
     * @param examinationOption
     * @return
     */
    @Override
    public boolean createExaminationOption(ExaminationOption examinationOption) {
        return save(examinationOption);
    }


    /**
     * 修改题目选项
     * @param examinationOption
     * @return
     */
    @Override
    public boolean updateExaminationOption(ExaminationOption examinationOption) {
        return updateById(examinationOption);
    }


    /**
     * 通过题目id删除题选项
     * @param id
     */
    @Override
    public void deleteExaminationOptionByBank(String id) {
        examinationOptionMapper.delete(new QueryWrapper<ExaminationOption>()
                .lambda()
                .eq(ExaminationOption::getExaminationId,id)
        );
    }


    /**
     * 通过题id查出选项
     * @param id
     * @return
     */
    @Override
    public List<ExaminationOptionDto> findExaminationOption(String id) {
        List<ExaminationOption> examinationOptions = examinationOptionMapper.selectList(new QueryWrapper<ExaminationOption>()
                .lambda()
                .eq(ExaminationOption::getExaminationId, id)
        );

        return dozerUtils.mapList(examinationOptions, ExaminationOptionDto.class);
    }
}
